
class Info extends egret.Sprite{
	
	txtScore:egret.TextField;
	txtLevel:egret.TextField;

	grid:Grid;
	public constructor(g:Grid){
		super();
		this.txtLevel = new egret.TextField();
		this.txtLevel.width = 500;
		this.txtLevel.height = 30;
		this.txtLevel.y = 10;
		this.addChild(this.txtLevel);
		this.txtScore= new egret.TextField();
		this.txtScore.width = 500;
		this.txtScore.height = 30;
		this.txtScore.y = 50;
		this.addChild(this.txtScore);
		this.grid = g;
		this.grid.addEventListener(Grid.GAME_OVER,this.onGameOver,this);
		this.grid.addEventListener(Grid.LEVEL_UP,this.onLevelUp,this);
		this.grid.addEventListener(Grid.BOOM,this.onBoom,this);
		this.grid.addEventListener(Grid.CREATE_ITEM,this.onCreateItem,this);

		this.setLevel();
		this.setScore();
	}

	onCreateItem(e:egret.Event):void{
		let item:Item = this.grid.nextItem;
		item.y = 100; 
		this.addChild(item);
	}

	onBoom(e:egret.Event):void{
		this.setScore();
	}

	onLevelUp(e:egret.Event):void{
		this.setLevel();
	} 

	onGameOver(e:egret.Event):void{
		this.setLevel();
		this.setScore();
	}

	setLevel():void{
		this.txtLevel.text = "level:" + String(this.grid.curLevel); 
	}

	setScore():void{
		this.txtScore.text = "score:" + String(this.grid.score); 
	}
}
